package com.hualan.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebFilter(urlPatterns = "/*")
public class ServiceFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse resp = (HttpServletResponse) servletResponse;
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        if(req.getServletPath().endsWith(".html")||req.getServletPath().endsWith(".htm")){
            resp.setHeader("Content-type","text/html;charset=utf-8");
        }else{
            resp.setHeader("Content-type","text/json;charset=utf-8");
        }
        filterChain.doFilter(req,resp);
    }
}
